package com.erhya.export.poi.chain.poi;

import com.erhya.export.poi.PoiExcelTemplate;
import com.erhya.export.poi.chain.ExcelChina;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;

public class PoiNewSheetExcelExecute<T> extends ExcelChina<T> {

    private PoiExcelTemplate<T> excelTemplate;

    public PoiNewSheetExcelExecute(PoiExcelTemplate<T> excelTemplate) {
        this.excelTemplate = excelTemplate;
    }

    @Override
    public void execute(String fileName) throws Exception{
        Workbook workbook = excelTemplate.getWorkbook();
        if (workbook == null && super.workBook == null){
            workbook = new HSSFWorkbook();
            super.workBook = workbook;
        }

        excelTemplate.setWorkbook((HSSFWorkbook) workBook);

        if (successor != null ){

            excelTemplate.china(fileName, true);

            successor.setWorkBook(super.workBook);
            successor.execute(fileName);
            return;
        }

        excelTemplate.china(fileName, false);

    }

}
